package com.woniuxy.controller;


import java.security.Principal;
import java.util.HashMap;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.woniuxy.dto.PageDto;
import com.woniuxy.entity.Orders;
import com.woniuxy.entity.User;
import com.woniuxy.service.LogService;
import com.woniuxy.service.OrderService;

@RestController
@RequestMapping("/order")
public class OrderController {
	@Autowired
	private OrderService orderService;
	@Autowired
	private LogService logservice;
	//通过用户id查找所有的订单
	@RequestMapping("/find")
	public PageDto<Orders> find(int page){
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();
		User user = (User)session.getAttribute("user");
		
		PageDto<Orders> orders = orderService.find(user.getU_id(),page);
		System.out.println("sdasgreg"+orders);
		return orders;
		
	}
	//根据订单id删除订单
	@RequestMapping("/del")
	public int del(int o_id ,String order_no) {
		System.out.println("odedasfas"+order_no);
		
		//添加日志信息
		logservice.addorderLogbuyer(order_no);
		
		
		return orderService.del(o_id);
		
		
		
	}
	//查找卖家订单
	@RequestMapping("/findsellerorders")
	public PageDto<Orders> findsellerorders(int page){
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();
		User user = (User)session.getAttribute("user");
		
		PageDto<Orders> orders = orderService.findsellerorders(user.getU_id(), page);
		return orders;
		
	}
	
	
	
	//查找订单详情
		@RequestMapping("/findorderdetail")
		public HashMap<String, Object> findorderdetail(int orderid) {
			Subject currentUser = SecurityUtils.getSubject();
			Session session = currentUser.getSession();
			User user = (User)session.getAttribute("user");
			
			return orderService.findorderdetail(orderid, user.getU_id());
			
		}
}
